/**
 * ------------------------------------------------------------*
 *          COPYRIGHT (C) 2006 BOCO Inter-Telecom INC          *
 *   CONFIDENTIAL AND PROPRIETARY. ALL RIGHTS RESERVED.        *
 *                                                             *
 *  This work contains confidential business information       *
 *  and intellectual property of BOCO  Inc, Beijing, CN.       *
 *  All rights reserved.                                       *
 * ------------------------------------------------------------*
 *
 *
 */
/**
 *Revision Information:
 *
 *@version 1.0 2006-4-26 release(wuyanfen)
 */


package com.boco.webmaster.model;

import java.util.*;
import com.boco.transnms.server.bo.misc.EnumBO;
import com.boco.transnms.client.model.base.IBoCommand;
import com.boco.transnms.client.model.base.BoCmdFactory;
import com.boco.transnms.server.bo.helper.misc.EnumBOHelper;
import com.boco.transnms.common.dto.base.DataObjectList;
import com.boco.transnms.common.dto.Room;
import com.boco.transnms.common.dto.base.BoActionContext;
import com.boco.common.util.lang.GenericEnum;

public class RoomTypeModel {
    private static RoomTypeModel instance = new RoomTypeModel();
    private Map roomTypeMap = new HashMap();
    public RoomTypeModel() {
        refresh();
    }

    public void refresh(){
        String enmuName = EnumBO.EnumName.ROOM_CFG_TYPE;
        IBoCommand cmd = BoCmdFactory.getInstance().createBoCmd(EnumBOHelper.ActionName.getEnum, new Object[] {enmuName});
        GenericEnum roomType = (GenericEnum) cmd.exec();
        String[] roomTypeEnum = roomType.getAllNames();
        for (int i = 0; i < roomTypeEnum.length; i++) {
            roomTypeMap.put(roomType.getValue(roomTypeEnum[i]),roomTypeEnum[i]);
        }
    }
    public static RoomTypeModel getInstance() {
        return instance;
    }

    public String getValue(long key) {
        return (String) roomTypeMap.get(key);
    }

    public Object[] getKeys() {
        return roomTypeMap.keySet().toArray();
    }

    /*public DataObjectList getAllRoom() {
        DataObjectList dbos = new DataObjectList();
        Iterator i = roomTypeMap.keySet().iterator();
        while (i.hasNext()) {
            String room_cuid = (String) i.next();
            Room dbo = (Room) roomTypeMap.get(room_cuid);
            dbos.add(dbo);
        }
        return dbos;
    }*/

    public long getValueByName(String label_cn){
        Iterator i = roomTypeMap.keySet().iterator();
        while (i.hasNext()) {
            Long cuid = (Long) i.next();
            String name = (String) roomTypeMap.get(cuid);
            if (name.equals(label_cn)) {
                return  cuid;
            }
        }
        return -1;
    }

    public void addroomType(long key, String value) {
        roomTypeMap.put(key, value);
    }

    public void delroomType(long key) {
        roomTypeMap.remove(key);
    }

    public void modifyroomType(long key, String value) {
        roomTypeMap.remove(key);
        roomTypeMap.put(key, value);
    }

}
